<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>
<link href="${ctx}/css/main/base.css" rel="stylesheet" type="text/css"/>
<link href="${ctx}/css/main/main.css" rel="stylesheet" type="text/css"/>
<body class="m_r">
<div id="main">
<div id="info"><font color="red">${info}</font></div>
<form action="depart_create.action" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tab_1">
  <caption>新建部门－当前节点：[${unit.unitName}]</caption>
  <tr>
    <td class="w1">部门排序号：</td>
    <td><input type="text" id="deptOrder" name="department.deptOrder" size="5" class="fl_l" /><div id="errOrder"></div>
      用于处于同一层次部门的排序，以及用户列表的排序</td>
  </tr>
  <tr>
    <td class="w1">部门名称：</td>
    <td><input type="text" id="deptName" name="department.deptName" class="fl_l" /><div id="errName"></div></td>
  </tr>
  <tr>
    <td class="w1">部门电话：</td>
    <td><input type="text" id="deptTel" name="department.deptTel" class="fl_l" /><div id="errTel"></div></td>
  </tr>
  <tr>
    <td class="w1">部门传真：</td>
    <td><input type="text" id="deptFax" name="department.deptFax" class="fl_l" /><div id="errFax"></div></td>
  </tr>
  <tr>
    <td class="w1">上级部门：</td>
    <td><select name="department.deptParent">
    <option value="0">--请选择上级部门--</option>
    <s:iterator value="departments" status="depart">
    <option value="${deptId}" <s:if test="department.deptParent == deptId">selected</s:if>>${deptNames}</option>
   </s:iterator>
    </select> </td>
  </tr>
  <tr>
    <td class="w1">部门职能：</td>
    <td><textarea class="text1" name="department.deptFunc"></textarea></td>
  </tr>
  <tr>
    <td class="w1">部门主管：</td>
    <td><input type="hidden" id="deptManager" name="department.deptManager"/>
    <textarea class="text1" name="deptManagerName"></textarea>
    <input type="button" onclick="chooseLeaders('deptManager','deptManagerName');" value="+添加" class="log_f">
     <input type="button" onclick="deleteChoose('deptManager','deptManagerName');" value="-清空" class="log_f">
    </td>
  </tr>
  <tr>
    <td class="w1">上级主管领导：</td>
    <td>
    <input type="hidden" id="deptLeader1" name="department.deptLeader1"/>
    <textarea class="text1" name="deptLeader1Name"></textarea>
      <input type="button" onclick="chooseLeaders('deptLeader1','deptLeader1Name');" value="+添加" class="log_f">
     <input type="button" onclick="deleteChoose('deptLeader1','deptLeader1Name');" value="-清空" class="log_f">
    </td>
  </tr>
  <tr>
    <td class="w1">上级分管领导：</td>
    <td><input type="hidden" id="deptLeader2" name="department.deptLeader2"/>
    <textarea class="text1" name="deptLeader2Name"></textarea>
    <input type="button" onclick="chooseLeaders('deptLeader2','deptLeader2Name');" value="+添加" class="log_f">
     <input type="button" onclick="deleteChoose('deptLeader2','deptLeader2Name');" value="-清空" class="log_f">
    </td>
  </tr>
  <tr>
    <td colspan="2"><div class="zc_but2">
	<input type="button" onclick="createDepart();" value="新 建" class="log_f zc_b">
	<input type="button" onclick="javascript:reset();" value="重置" class="log_f zc_b">
	<input type="button" onclick="javascript:history.go(-1);" value="返回" class="log_f zc_b">
	</div></td>
    </tr>
  </table>
</div>
</form>
</body>
</html>
<script type="text/javascript" src="${ctx}/scripts/commons/validation.js"></script>
<script type="text/javascript">
<!--
function createDepart(){
 var deptName = document.getElementById("deptName").value;
 var deptOrder = document.getElementById("deptOrder").value;
 var deptTel = document.getElementById("deptTel").value;
 var deptFax = document.getElementById("deptFax").value;
 
 
 if(deptOrder.length == 0 || deptOrder == ""){
    document.getElementById("errOrder").innerHTML = "<font color='red'>部门排序不能为空!</font>";
	   return false;
 }
 if(isNaN(parseInt(deptOrder))){
    document.getElementById("errOrder").innerHTML = "<font color='red'>部门排序必须是数字!</font>";
	   return false;
 }
 if(deptOrder.length > 4){
    document.getElementById("errOrder").innerHTML = "<font color='red'>部门排序长度不能超过4!</font>";
	   return false;
 }
 if(deptName.length == 0 || deptName == ""){
    document.getElementById("errName").innerHTML = "<font color='red'>部门名称不能为空!</font>";
	   return false;
 }
 if(deptName.length > 0 && hasSpecialChart(deptName)){
	document.getElementById("errName").innerHTML = "<font color='red'> 部门名称不能有特殊字符!</font>";
		return false;
}
 if(deptName.length > 50){
	document.getElementById("errName").innerHTML = "<font color='red'> 部门名称长度不能超过50!</font>";
		return false;
}
if(deptTel.length > 0 && !isAllNumber(deptTel)){
	document.getElementById("errTel").innerHTML = "<font color='red'> 正确填写电话号码!</font>";
	return false;
}
if(deptTel.length > 20 ){
	document.getElementById("errTel").innerHTML = "<font color='red'> 正确填写电话号码!</font>";
	return false;
}
if(deptFax.length > 20){
	document.getElementById("errFax").innerHTML = "<font color='red'> 正确填写传真号码!</font>";
	return false;
}
document.forms[0].submit();
	
}


function deleteChoose(id,name){
		document.getElementById(id).value = "";
    	document.getElementById(name).value = "";
	}
	
	
function chooseLeaders(id,name){

	var names ="";
    var ids ="";
	var item=window.showModalDialog("${ctx}/user/user!chooseUser.action?time="+new Date().getTime(),window,"scroll:no;dialogHeight=420px;dialogWidth=420px;");
    if(item != null){
    for(var i=0;i<item.length;i++)
       {
          names += item[i][0]+",";
          ids += item[i][1]+",";
       }
     
   	document.getElementById(id).value = ids;
   	document.getElementById(name).value = names;
}
}
//-->
</script>
